package com.ele.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ele.mapper.SwiperMapper;
import com.ele.pojo.ResponseData;
import com.ele.pojo.Swiper;
import com.ele.service.SwiperService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SwiperServiceImpl implements SwiperService {
    @Resource
    private SwiperMapper swiperMapper;

    @Override
    public ResponseData<Swiper> swiperList() {
        // 查询轮播图列表，只能查询没有被禁用的轮播图数据，
        // swiper 表中的 useable 的值为0的才能查询出来
        // mybatisplus提供的用于书写查询条件的类
        QueryWrapper<Swiper> wrapper = new QueryWrapper<>();
        wrapper.eq("useable", 0);
        List<Swiper> swipers = this.swiperMapper.selectList(wrapper);
        ResponseData<Swiper> responseData = new ResponseData<>();
        if(swipers != null && !swipers.isEmpty()){
            responseData.setCode(20000);
            responseData.setDatas(swipers);
        }else{
            responseData.setCode(50000);
            responseData.setMessage("没有查询到数据");
        }
        return responseData;
    }
}